package com.eazy.lkv2.web.controller.system.count;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.eazy.lkv2.core.web.utils.ResultVO;
import com.eazy.lkv2.web.controller.BaseController;
import com.eazy.lkv2.web.entity.LoginLog;
import com.eazy.lkv2.web.service.system.count.BaiduService;

/**
 * 集成百度地图
 */
@Controller
@RequestMapping("/baidu")
public class BaiduCountController extends BaseController {

	@Autowired
	private BaiduService baiduService;

	@RequestMapping(value = "list", method = RequestMethod.GET)
	public String list() {
		return "/sys/baidu_log";
	}

	@RequestMapping(value = "getLocations", method = RequestMethod.GET)
	public void getLocations() {
		ResultVO resultVO = new ResultVO(true);

		List<Map<String, Double>> mapList = new ArrayList<>();
		List<LoginLog> result = baiduService.queryByList(null);
		for (LoginLog loginLog : result) {
			if (loginLog.getPointX() != null && loginLog.getPointY() != null) {
				BigDecimal pointX = new BigDecimal(loginLog.getPointX().toString());
				BigDecimal pointY = new BigDecimal(loginLog.getPointY().toString());
				if (pointX != null && pointY != null) {
					Map<String, Double> map = new HashMap<>();
					map.put("x", pointX.doubleValue());
					map.put("y", pointY.doubleValue());
					mapList.add(map);
				}
			}
		}
		resultVO.setData(mapList);
		renderJson(resultVO);
	}
}
